package org.training.apr.dao.fake;


import java.util.List;

import org.training.apr.dao.EnterpriseDao;
import org.training.apr.model.Enterprise;
import org.training.apr.model.utils.builder.EnterpriseBuilder;

public final class FakeEnterpriseDao extends FakeDao<Enterprise> implements EnterpriseDao {
	private static EnterpriseDao instance = null;
	
	public static EnterpriseDao getInstance() {
		init();
		return instance;
	}

	public static void init() {
		if(instance == null) {
			instance = new FakeEnterpriseDao();
		}
	}
	
	private FakeEnterpriseDao() {
		Enterprise enterprise = new EnterpriseBuilder().build();
		
		Enterprise tap = new EnterpriseBuilder().withName("TAP").build();
		Enterprise megasis = new EnterpriseBuilder().withName("Megasis").build();
		Enterprise groundForce = new EnterpriseBuilder().withName("Ground Force").build();
		Enterprise maintenenceAndEngineering = new EnterpriseBuilder().withName("Maintenance & Engineering").build();
		
		tap.addChild(megasis);
		tap.addChild(groundForce);
		tap.addChild(maintenenceAndEngineering);
		
		save(enterprise);
		save(tap);
		save(megasis);
		save(groundForce);
		save(maintenenceAndEngineering);
	}

	public List<Enterprise> findByName(final String name) {
		return findByCriteria(new Criteria<Enterprise>() {
			public boolean evaluate(Enterprise instance) {
				return instance.getName().equalsIgnoreCase(name);
			}
		});
	}
}
